package com.hourse.platform.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.Set;

/**
 * @使用描述: AppTools
 */
@Slf4j
public class AppTools {

  /**
   * @功能描述: 【获取当前用户ID】
   * @return : java.lang.String
   */
  public static String GetCurrentUserId(){
    return CurrentThread.getUserId();
  }
  /**
   * @功能描述: 【获取用户TOKEN】
   */
  public static String GetCurrentToken(){
    return CurrentThread.getToken();
  }

  public static boolean isAdmin(){

    return CurrentThread.isAdmin();
  }

  public static boolean isRole(String role){

    if(CurrentThread.getRoles() == null){
        log.warn(" 警告: 当前用户角色为 NULL");
        return false;
    }
    return CurrentThread.getRoles().contains(role);
  }

  public static Set<String> getRoles(){

    return CurrentThread.getRoles();
  }

  /**
   * 密码加密
   * @param account
   * @param password
   * @return
   */
  public static String EncryptionPassword(String account,String password) throws UnsupportedEncodingException, NoSuchAlgorithmException {
    String pass01 = StringTools.encoderByMd5(account);
    String pass02 = StringTools.encoderByMd5(password);
    String pass = StringTools.encoderByMd5(pass01 + pass02);
    return pass;
  }

  public static String getCurrentRoleGroupId() {
    return CurrentThread.getCurrentRoleId();
  }

  public static Object getCurrentEnterPriseId() {
    return CurrentThread.getCurrentEnterPriseId();
  }

}
